package cn.fintecher.pangolin.service.dataimp.request;

import cn.fintecher.pangolin.common.enums.ImportDataExcelStatus;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.elasticsearch.index.query.BoolQueryBuilder;
import org.elasticsearch.index.query.QueryBuilder;
import org.elasticsearch.index.query.QueryBuilders;

import java.util.Objects;

/**
 * @Auther: xiaqun
 * @Description: 查询分案导入结果请求参数
 * @Date: 13:49 2019/10/18
 */

@Data
public class FindDistributeRecordRequest {
    @ApiModelProperty(value = "委托方ID")
    private String principalId;

    @ApiModelProperty(value = "数据导入状态")
    private ImportDataExcelStatus status;

    public BoolQueryBuilder getBuilder() {
        BoolQueryBuilder builder = new BoolQueryBuilder();
        if (Objects.nonNull(this.principalId)) {
            builder.must(QueryBuilders.matchPhraseQuery("principalId.keyword", this.principalId));
        }
        if (Objects.nonNull(this.status)) {
            builder.must(QueryBuilders.matchPhraseQuery("status.keyword", this.status.name()));
        }
        return builder;
    }
}
